package com.springboot.wk.aqs;

import java.util.concurrent.atomic.AtomicBoolean;

public class MyLock {

    //锁
    private AtomicBoolean flag = new AtomicBoolean(false);

    //持有锁的线程
    private Thread owner;

    void lock() {

        while (!flag.compareAndSet(false, true)) {
            System.out.println(Thread.currentThread().getName() + "获取锁");
            break;
        }
    }

    void unlock() {
        flag.set(false);
    }
}
